package hsintiao.com.xintiaoAPP.controller;


import hsintiao.com.xintiaoAPP.entity.Doctor;
import hsintiao.com.xintiaoAPP.service.DoctorService;
import hsintiao.com.xintiaoAPP.util.AjaxResult;
import hsintiao.com.xintiaoAPP.util.ResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
* 医生列表
* */
@RestController
@RequestMapping("/doctor")
@CrossOrigin
public class DoctorController {
    @Autowired
    private DoctorService doctorService;

    /*
    * 获取医生列表
    * */
    @PostMapping("/getAll")
    @ResponseBody
    public AjaxResult findAll(){
        AjaxResult result = doctorService.findAll();
        return result;
    }
    /*
    * 根据医生的id获取对应的医生的具体信息
    * */
    @PostMapping("/getOneById")
    @ResponseBody
    public AjaxResult getOneById(@RequestBody Doctor doctor){
        try {
            Long id = doctor.getId();
            AjaxResult result = doctorService.findOneById(id);
            return result;
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setCode(ResponseCode.FAILURE.getCode())
                    .setSuccess(false).setMessage("查询失败");
        }
    }
}
